﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace Ewts.RDLC
{
    public partial class CJONonlocalRDLC : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int cjoID = 0;
                DataLib.Model.CJOItem cjoIteM = new DataLib.Model.CJOItem();
                if (Request["cjoID"] != null && Request["cjoID"].ToString().Trim() != "")
                {
                    cjoID = int.Parse(Request["cjoID"].ToString().Trim());
                    //GetReportMultipleDataSourceFile
                }

                try
                {
                    cjoIteM = new DataLib.BLL.CJOItem().GetListByCid(cjoID);
                    BindData(cjoIteM);
                }
                catch(Exception ex)
                {
                    DataLib.Common.MessageBox.Show(Page,ex.Message);
                }
                finally { }
            }
        }

        /// <summary>
        /// 数据绑定
        /// </summary>
        /// <param name="cjoIteM"></param>
        protected void BindData(DataLib.Model.CJOItem cjoIteM)
        {
            List<ReportParameter> parameterList = new List<ReportParameter>();

            DataLib.Model.LoadNum loadModel = new DataLib.BLL.LoadNum().GetModel(cjoIteM.loadnumid);
            DataLib.Model.CumtomerAddress addrModel = new DataLib.BLL.CumtomerAddress().GetModel(int.Parse(cjoIteM.Addressid.ToString()));
            DataLib.Model.Cumtomer cusModel = new DataLib.BLL.Cumtomer().GetModel(cjoIteM.customerid);
            DataLib.Model.Cjo cModel = new DataLib.BLL.Cjo().GetModel(cjoIteM.cjoid);
            DataLib.Model.VehicleRequire vrModel = new DataLib.BLL.VehicleRequire().GetModel(cjoIteM.vehichlerequireid);

            //报表信息为主参数
            parameterList.Add(new ReportParameter("CreateTime", cjoIteM.createtime.ToString()));
            parameterList.Add(new ReportParameter("LoadNum", cjoIteM.loadnumno));
            parameterList.Add(new ReportParameter("CollectDate", cjoIteM.CjoColldate.ToString()));
            parameterList.Add(new ReportParameter("CustomerName", cjoIteM.companyname));
            parameterList.Add(new ReportParameter("WorkerCount", cjoIteM.workercount.ToString()));
            parameterList.Add(new ReportParameter("Vehicle", cjoIteM.other.ToString()));
            parameterList.Add(new ReportParameter("GoodsCount", cjoIteM.numberestimate.ToString()));
            parameterList.Add(new ReportParameter("paramOther", cjoIteM.other));
       
            parameterList.Add(new ReportParameter("GoodsWeight", loadModel.totalWeight.ToString()));
            if (cjoIteM.goodsdesc != null)
            {
                parameterList.Add(new ReportParameter("GoodsInfo", cjoIteM.goodsdesc.Replace("@", " ").Replace("|", " ")));
            }
            

            parameterList.Add(new ReportParameter("ContactPerson", cModel.cjolinkman));
            parameterList.Add(new ReportParameter("ContactPhone", cModel.cjophone));
            parameterList.Add(new ReportParameter("CustomerAddress", cModel.cjoadd));
            parameterList.Add(new ReportParameter("PayType", vrModel.clearingform));

           // DataLib.Accounts.Bus.User user = new DataLib.Accounts.Bus.User(loadModel.saleman);
            parameterList.Add(new ReportParameter("PhoneNum", cModel.cjophone));
            parameterList.Add(new ReportParameter("SalesMan", cjoIteM.Saleman));

            string [] arrGoods = GetGoodsArr(cjoIteM.goodsdesc,0);
            string[] arrqty = GetGoodsArr(cjoIteM.goodsdesc, 1);

            parameterList.Add(new ReportParameter("paramgoods1", arrGoods[0]));
            parameterList.Add(new ReportParameter("paramgoods2", arrGoods[1]));
            parameterList.Add(new ReportParameter("paramgoods3", arrGoods[2]));
            parameterList.Add(new ReportParameter("paramgoods4", arrGoods[3]));
            parameterList.Add(new ReportParameter("paramgoods5", arrGoods[4]));
            parameterList.Add(new ReportParameter("paramgoods6", arrGoods[5]));
            parameterList.Add(new ReportParameter("paramgoods7", arrGoods[6]));
            parameterList.Add(new ReportParameter("paramgoods8", arrGoods[7]));
            parameterList.Add(new ReportParameter("paramgoods9", arrGoods[8]));
            parameterList.Add(new ReportParameter("paramgoods10", arrGoods[9]));
            parameterList.Add(new ReportParameter("paramgoods11", arrGoods[10]));
            parameterList.Add(new ReportParameter("paramgoods12", arrGoods[11]));

            parameterList.Add(new ReportParameter("paramqty1", arrqty[0]));
            parameterList.Add(new ReportParameter("paramqty2", arrqty[1]));
            parameterList.Add(new ReportParameter("paramqty3", arrqty[2]));
            parameterList.Add(new ReportParameter("paramqty4", arrqty[3]));
            parameterList.Add(new ReportParameter("paramqty5", arrqty[4]));
            parameterList.Add(new ReportParameter("paramqty6", arrqty[5]));
            parameterList.Add(new ReportParameter("paramqty7", arrqty[6]));
            parameterList.Add(new ReportParameter("paramqty8", arrqty[7]));
            parameterList.Add(new ReportParameter("paramqty9", arrqty[8]));
            parameterList.Add(new ReportParameter("paramqty10", arrqty[9]));
            parameterList.Add(new ReportParameter("paramqty11", arrqty[10]));
            parameterList.Add(new ReportParameter("paramqty12", arrqty[11]));
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.SetParameters(parameterList);
            ReportViewer1.LocalReport.Refresh();

        }

        public string[] GetGoodsArr(string goodsinfo,int flag)
        {
            string[] arrgoods = new string[12];
            string[] tarr;
            if (goodsinfo.IndexOf('|') >= 0)
            {
                tarr = goodsinfo.Split('|');
                for (int i = 0; i < tarr.Length; i++)
                {
                    try
                    {
                        arrgoods[i] = tarr[i].Split('@')[flag];
                    }
                    catch
                    {
                        arrgoods[i] = "";
                    }
                }
            }
            return arrgoods;
        }
    }
}